$().ready(function() {
	validateRule();
    getDeviceTypeByUpdate(getTypeId())
    formatDate()
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});

// function getTypeId() {
// 	var typeId = $("#deviceTypeId").val();
// 	return typeId;
// }



function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : getProjectName()+"/device/device/update",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
        rules : {
            deviceName : {
                required : true
            },
            signal : {
                required : true
            },
            useFarm : {
                required : true
            },
            useDate : {
                required : true
            },
            number : {
                required : true
            },
            produceFactory : {
                required : true
            },
            quality : {
                required : true
            }
        },
        messages : {
            deviceName : {
                required : icon + "请填写设备名称"
            },
            signal : {
                required : icon + "请填写设备型号"
            },
            useFarm : {
                required : icon + "请填写使用车间"
            },
            useDate : {
                required : icon + "请填写使用时间"
            },
            number : {
                required : icon + "请填写数量"
            },
            produceFactory : {
                required : icon + "请填写生产厂家"
            },
            quality : {
                required : icon + "请填写材质"
            }
        }
	})
}